package org.gruposp2p.aula.gwt.client.representation;

import org.gruposp2p.aula.gwt.client.model.Course;
import org.restlet.gwt.resource.XmlRepresentation;
import com.google.gwt.core.client.GWT;
import com.google.gwt.xml.client.Attr;
import com.google.gwt.xml.client.Element;

public class CourseRepresentation {
	
	public CourseRepresentation () {}

	private XmlRepresentation xmlRepresentation;	
	
	public void setXmlRepresentation(XmlRepresentation xmlRepresentation) {
		this.xmlRepresentation = xmlRepresentation;
		/*
		for (RepresentationListener listener : listeners) {
			listener.loadRepresentation(this);
		}*/
	}
	
	public XmlRepresentation getXmlRepresentation () {
		return xmlRepresentation; 
	}
	
	public Course getCourse() {
		Course course = new Course();
		
		Element courseElement = xmlRepresentation.getDocument().getDocumentElement();
		
		String nombre = courseElement.getAttribute("nombre");
		GWT.log("nombre: " + nombre, null);		
		
		Attr descripcion = courseElement.getAttributeNode("descripcion");
		GWT.log("descripcion.getNodeValue(): " + descripcion.getNodeValue(), null);
		
		/*
        Node courseNode = xmlRepresentation.getDocument().
        		getElementsByTagName("curso").item(0);
        GWT.log("courseNode.toString(): " + courseNode.toString(), null);
        NamedNodeMap attributes = courseNode.getAttributes();
        attributes.
        
        NodeList nodes1 = xmlRepresentation.getDocument().getDocumentElement().getChildNodes();
        //nodes1.
        
        Node courseNode = nodes.item(0);
        courseNode.
        //courseNode.get
        
        for (int i = 0; i < nodes.getLength(); i++) {
                Node node = nodes.item(i);
                message = message + "Node: " + node.getNodeName() + "- Node value: " + node.getFirstChild().getNodeValue() + "<br/>";
        }*/
        return course;
	} 
	
	
}
